﻿@using Model.WXshopBuiness
@using Xproject.Util
@{
    Layout = null;
    
    string Domain = CommonHelper.GetAppSettings("Domin");
}
@model Address

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <link href="~/Content/css/shop/home.css" rel="stylesheet" />

    <link href="http://at.alicdn.com/t/font_u5tafk2orz281tt9.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/layerui/need/layer.css" rel="stylesheet" />
    <script src="~/Content/layerui/layer.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="~/Scripts/distpicker/distpicker.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/shop/index.js"></script>
   
    <style>
        .form-group {
            border-bottom: 1px solid #ececec;
            overflow: hidden;
            margin-top: 5px;
            margin-bottom: 0;
        }

            .form-group .col-xs-4 {
                padding-left: 0;
                color: #333;
            }

            .form-group .col-xs-8 {
                padding: 0;
            }

        .control-label {
            line-height: 2.143em;
            text-align: right;
        }

        .form-control {
            box-shadow: none;
            padding: 0 0.429em;
            height: 2.143em;
            border: none;
        }
    </style>
</head>
<body>


    <div class="container body-content" style="background:#fff; padding-left:0px;padding-right:0px;">




        <div class="top_c">
            <a href="@(Domain)/Address/MyAddress" class="iconfont icon-jiantou-copy-copy"></a>
            <p class="titi">收货地址</p>
        </div>
        <div id="editContent">
            <div class="cong">
                <div class="container" style="background:#fff; padding-left:0px;padding-right:0px;">
                    <div class="form-group">
                        <label for="Receiver" class="col-xs-4 control-label" style="text-align:left;padding:0;margin:0">收货人姓名</label>
                        <div class="col-xs-8">
                            <input class="form-control" name="Receiver" id="Receiver" placeholder="请输入收货人的姓名" value="@(Model!=null?Model.Receiver:"")" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Phone" class="col-xs-4 control-label" style="text-align:left;padding:0;margin:0">手机号码</label>
                        <div class="col-xs-8">
                            <input class="form-control" name="Phone" id="Phone" placeholder="请输入您的手机号码" required value="@(Model!=null?Model.Phone:"")">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="PostCode" class="col-xs-4 control-label" style="text-align:left;padding:0;margin:0">邮编</label>
                        <div class="col-xs-8">
                            <input class="form-control" name="PostCode" id="PostCode" placeholder="请输入邮编" required value="@(Model!=null?Model.PostCode:"")">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-xs-12 control-label" style="text-align:left;padding:0;margin:0">省市区</label>
                        <div class="col-xs-12">
                            <div id="distpicker">
                                <select class="control col-xs-4" id="sheng"></select>
                                <select class="control col-xs-4" id="shi"></select>
                                <select class="control col-xs-4" id="quyu"></select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group" style="border-bottom:none;">
                        <label for="DetailAddress" class="col-xs-12 control-label" style="text-align:left">详细地址</label>
                        <div class="col-xs-12">
                            <textarea name="DetailAddress" id="DetailAddress" placeholder="请输入您的详细地址" cols="3" rows="3" style="width:90%" required>@(Model!=null?Model.DetailAddress:"")</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Tag" class="col-xs-4 control-label" style="text-align:left;padding:0;margin:0">标签</label>
                        <div class="col-xs-8">
                            <input class="form-control" id="Tag" name="Tag" placeholder="请输入标签" value="@(Model!=null?Model.Tag:"")">
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="checkbox" class="checkbox" id="IsDefault" name="IsDefault" style="width:10px;float:left"><span>设为默认</span>
                    </div>
                    </div>
                    <div class="container">
                        <input id="addressId" name="addressId" type="hidden" value="@(Model!=null?Model.AddressID:"")" />
                        <button onclick="saveit()" class="deng" style="margin-top:3em;">保 存</button>
                    </div>
                </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {

            var province = '@(Model!=null?Model.Sheng:"")';
            var city = '@(Model!=null?Model.Shi:"")';
            var district = '@(Model!=null?Model.QuYu:"")';

            $('#distpicker').distpicker(
                {
                    province: province,
                    city: city,
                    district: district
                }
            );
    });

    function saveit() {
        var addressId = $("#addressId").val();
        var sheng = $("#sheng").val();
        var shi = $("#shi").val();
        var quyu = $("#quyu").val();
        var DetailAddress = $("#DetailAddress").val();
        var Phone = $("#Phone").val();
        var PostCode = $("#PostCode").val();
        var Receiver = $("#Receiver").val();
        var isDefault = $("#IsDefault").prop('checked');
        var Tag = $("#Tag").val();
        var errorstr = "";
        var flag = true; 
        if (DetailAddress == '') {
            flag = false;
            errorstr = "没有填写详细地址哦";
        }
        if (sheng == '' || shi == '' || quyu == '') {
            flag = false;
            errorstr = "没有填写所在省市区";
        }        
        if (Phone == '') {
            flag = false;
            errorstr = "没有填写手机号码";
        }
        if (Receiver == '') {
            flag = false;
            errorstr = "没有填写收件人哦";
        }
        if (Phone != '') {
            var mobilePatternHK = /^(\+852\s)?[5689]{1}\d{7}$/;
            if ((/^1[34578]\d{9}$/.test(Phone)) || mobilePatternHK.test(Phone)) {

                // flag = true;
            } else {
                errorstr = ("手机号码有误，请重填");
                flag = false;
            }

        }
     
        if (flag == false) {
            layer.open({
                content: errorstr
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
            return;
        }
      
           $.ajax({
            type: "POST",
            url: '@(Domain)/Address/EditAddr',
            data: {
                addressId: addressId, sheng: sheng, shi: shi, quyu: quyu, DetailAddress: DetailAddress, Phone: Phone, PostCode: PostCode,
                Receiver: Receiver, Tag: Tag, IsDefault: isDefault},
            cache: false,

            success: function (data) {
                layer.open({
                    content: data.Data
                    , skin: 'msg'
                    , time: 2 //2秒后自动关闭
                });
            }
        });
    }

    </script>
</body>
</html>